package com.monkeygroup.mygoplus.view.home.activity.person;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.common.DefinedView.PickerView;

import java.util.ArrayList;
import java.util.List;

/**
 * 基本設定
 * Created by cumt on 2017/6/27.
 */

public class PersonBaseSettingActivity extends BaseActivity implements View.OnClickListener {

    public static void gotoActivity(Activity activity) {
        Intent intent = new Intent(activity,
                PersonBaseSettingActivity.class);

        activity.startActivity(intent);
    }

    private ImageView imgBack,img_right;
    private TextView txtTitle;
    private LinearLayout layout_shortcut;

    private PopupWindow pickerpop;
    private RelativeLayout ll_set_time;

    private PickerView picker,choose_month_picker;
    @Override
    public void onClick(View v) {

    }

    @Override
    public void setContentView() {
        setContentView(R.layout.person_base_setting);
    }

    @Override
    public void initView() {

        imgBack = (ImageView) findViewById(R.id.img_back);
        txtTitle = (TextView) findViewById(R.id.txt_title);
        txtTitle.setText("基本設定");
        layout_shortcut= (LinearLayout) findViewById(R.id.layout_shortcut);
        layout_shortcut.setVisibility(View.VISIBLE);
        img_right= (ImageView) findViewById(R.id.img_right);
        img_right.setImageResource(R.mipmap.btn_me_info3x);


        ll_set_time= (RelativeLayout) findViewById(R.id.ll_set_time);
        initPickerPopwindow();


    }

    @Override
    public void setListener() {

    }

    @Override
    public void doEvent() {

        imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        layout_shortcut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PersonAboutUsActivity.gotoActivity(PersonBaseSettingActivity.this);
            }
        });

        ll_set_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pickerpop != null && pickerpop.isShowing()) {

                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }


                List<String> first = new ArrayList<String>();

                for(int i=0;i<48;i++){

                    if(i%2==0){
                        if(i/2<10){
                            first.add("0"+(i/2)+":30");
                        }
                        else{
                            first.add((i/2)+":30");
                        }
                    }
                    else{
                        if(i/2<10){
                            first.add("0"+(i/2)+":00");
                        }
                        else{
                            first.add((i/2)+":00");
                        }
                    }

                }

                picker.setData(first);

                choose_month_picker.setData(first);


            }
        });

    }

    private void initPickerPopwindow(){

        LayoutInflater myinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView=myinflater.inflate(R.layout.popwindow_picker, null);


        pickerpop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);

        pickerpop.setTouchable(true);

        LinearLayout  ll_picker= (LinearLayout)contentView.findViewById(R.id.ll_picker);
        ll_picker.setVisibility(View.GONE);

          picker= (PickerView)contentView.findViewById(R.id.choose_picker);
         choose_month_picker= (PickerView)contentView.findViewById(R.id.choose_month_picker);
        TextView  choose_year_unit= (TextView)contentView.findViewById(R.id.choose_year_unit);
        choose_year_unit.setText("~");
        choose_month_picker.setVisibility(View.VISIBLE);

        //  ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.backgroud_light_I));
        pickerpop.setBackgroundDrawable(new BitmapDrawable());

    }
}
